package country

import (
	"github.com/jinzhu/gorm"
	"time"
)

// CREATE TABLE `country_info` (
//
//	`id` int NOT NULL AUTO_INCREMENT,
//	`continent` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
//	`capital` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
//	`languages` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
//	`geoname_id` int DEFAULT NULL,
//	`south` double DEFAULT NULL,
//	`iso_alpha3` varchar(3) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
//	`north` double DEFAULT NULL,
//	`fips_code` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
//	`population` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
//	`east` double DEFAULT NULL,
//	`iso_numeric` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
//	`area_in_sq_km` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
//	`country_code` varchar(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
//	`west` double DEFAULT NULL,
//	`country_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
//	`continent_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
//	`currency_code` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
//	`create_by` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
//	`update_by` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
//	`create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
//	`update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
//	`delete_flag` tinyint(1) NOT NULL DEFAULT '0',
//	PRIMARY KEY (`id`) USING BTREE,
//	KEY `idx_country_code` (`country_code`) USING BTREE
//
// ) ENGINE=InnoDB AUTO_INCREMENT=213 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
type CountryInfo struct {
	Id            int       `json:"id" gorm:"primary_key;column:id"`
	Continent     string    `json:"continent" gorm:"column:continent"`
	Capital       string    `json:"capital" gorm:"column:capital"`
	Languages     string    `json:"languages" gorm:"column:languages"`
	GeonameId     int       `json:"geoname_id" gorm:"column:geoname_id"`
	South         float64   `json:"south" gorm:"column:south"`
	IsoAlpha3     string    `json:"iso_alpha3" gorm:"column:iso_alpha3"`
	North         float64   `json:"north" gorm:"column:north"`
	FipsCode      string    `json:"fips_code" gorm:"column:fips_code"`
	Population    string    `json:"population" gorm:"column:population"`
	East          float64   `json:"east" gorm:"column:east"`
	IsoNumeric    string    `json:"iso_numeric" gorm:"column:iso_numeric"`
	AreaInSqKm    string    `json:"area_in_sq_km" gorm:"column:area_in_sq_km"`
	CountryCode   string    `json:"country_code" gorm:"column:country_code"`
	West          float64   `json:"west" gorm:"column:west"`
	CountryName   string    `json:"country_name" gorm:"column:country_name"`
	ContinentName string    `json:"continent_name" gorm:"column:continent_name"`
	CurrencyCode  string    `json:"currency_code" gorm:"column:currency_code"`
	CreateBy      string    `json:"create_by" gorm:"column:create_by"`
	UpdateBy      string    `json:"update_by" gorm:"column:update_by"`
	CreateTime    time.Time `json:"create_time" gorm:"column:create_time"`
	UpdateTime    time.Time `json:"update_time" gorm:"column:update_time"`
	DeleteFlag    int       `json:"delete_flag" gorm:"column:delete_flag"`
}

func (c *CountryInfo) TableName() string {
	return "country_info"
}
func (c *CountryInfo) GetById(db *gorm.DB) error {
	return db.Table(c.TableName()).Where("id = ?", c.Id).First(c).Error
}
func (c *CountryInfo) GetCountryCode(db *gorm.DB) error {
	return db.Table(c.TableName()).Where("country_code = ?", c.CountryCode).First(c).Error
}
